<template>
	<view class=" " style="padding-bottom: 100upx;">
		<view class="headtop">
			<view class="u-flex padding text-white">
				<view class="u-m-r-10">
					<image :src="avatar" style="width: 100rpx;height: 100rpx;border-radius: 100rpx;"
						@click="goNav('/pages/my/userinfo')"></image>
				</view>
				<view class="u-flex-1  margin-left-xs" v-if="!isLogin">
					<view class=" flex margin-top-xs">
						<view class=" text-lg text-bold">{{userName}}</view>
						<view class="label" v-if="XCXIsSelect != '否'" style="font-size: 22rpx;font-weight: 500;">
							<view v-if="renzheng == 0" @click.stop="goNav('/my/renzheng/index')">
								未认证
							</view>
							<view v-if="renzheng == 1" @click.stop="goNav('/my/renzheng/index')">
								审核中
							</view>
							<view v-if="renzheng == 2" @click.stop="goNav('/my/renzheng/index')">
								已认证
							</view>
							<view v-if="renzheng == 3" @click.stop="goNav('/my/renzheng/index?companyId='+companyId)">
								已拒绝
							</view>
						</view>

					</view>
					<view class="text-26">商户号:{{consortiaNo}}</view>
				</view>
				<view v-else class="text-xl u-p-l-20 text-bold" @click="goLogin('/pages/public/login')">
					登录
				</view>
			</view>
			<view class="moneybox">
				<!-- <view class="flex align-center justify-between padding-lr padding-top">
					<view class="text-center">
						<view class="text-bold text-xl">{{succeedRate | formatPrice}}%</view>
						<view>成交率</view>
					</view>
					<view class="text-center">
						<view class="text-bold text-xl">{{sumCount}}</view>
						<view>服务次数</view>
					</view>
					<view class="text-center" @click="goNav('/my/wallet/xinyufendetail')">
						<view class="text-bold text-xl">{{creditScore}}</view>
						<view>信用分</view>
					</view>
				</view>
				<view
					style="border-bottom: 1rpx dashed #EEEEEE;width: 90%;margin: 0rpx auto;position: relative;top: 50rpx;">
				</view> -->
				<view class="padding" style="margin-top: 10rpx;">
					<view class="flex">
						<view class="" style="width: 50%;">
							<view style="color: #666666;">账户余额(元)</view>
							<view class="margin-top-xs" style="font-size: 35upx;">
								<text class="money_text">{{money?money:'0'}}</text>
							</view>
							<view style="color: #666666;font-size: 24rpx;" @click="goQian()">立即提现
								<image src="../../static/images/my/right.png"
									style="width:9rpx;height: 17rpx;margin-left: 10rpx;"></image>
							</view>
						</view>
						<view class="" style="width: 50%;">
							<view style="color: #666666;">本月提现</view>
							<view class="margin-top-xs" style="font-size: 35upx;">
								<text class="money_text">{{cashMoney?cashMoney:'0'}}</text>
							</view>
							<view style="color: #666666;font-size: 24rpx;" @click="goQian()">立即提现
								<image src="../../static/images/my/right.png"
									style="width:9rpx;height: 17rpx;margin-left: 10rpx;"></image>
							</view>
						</view>
					</view>
					<view class="flex ">
						<view class="" style="width: 50%;margin-top: 40rpx;" @click="goNav('/my/wallet/mymoneydetail')">
							<view style="color: #666666;">今日收益</view>
							<view class="margin-top-xs" style="font-size: 35upx;">
								<text class="money_text">{{toDayMoney?toDayMoney:'0'}}</text>
							</view>
						</view>
						<view class="" style="width: 50%;margin-top: 40rpx;" @click="goNav('/my/wallet/mymoneydetail')">
							<view style="color: #666666;">本月收益</view>
							<view class="margin-top-xs" style="font-size: 35upx;">
								<text class="money_text">{{monthMoney?monthMoney:'0'}}</text>
							</view>
						</view>
						<view class="" style="width: 50%;margin-top: 40rpx;" @click="goNav('/my/wallet/mymoneydetail')">
							<view style="color: #666666;">累计收益</view>
							<view class="margin-top-xs" style="font-size: 35upx;">
								<text class="money_text">{{sumMoney?sumMoney:'0'}}</text>
							</view>
						</view>
					</view>
				</view>
				<view style="width: 100%;height: 1rpx;background:#EEEEEE ;"></view>
				<view class="flex align-center justify-between padding-lr padding-tb-sm">
					<view class="text-black" style="font-family: PingFang SC;font-weight: 500;">
						每次提现平台将扣除相应手续费</view>
					<view class="xflist" @click="goNav('/my/wallet/mymoneydetail')">钱包明细</view>
				</view>
			</view>

			<view class="flex margin-top flex-wrap" style="padding-bottom: 30rpx;" v-if="XCXIsSelect != '否'">
				<view class="box" @click="goNav('/my/shop/index')">
					<image src="../../static/images/my/jishi.png"></image>
					<view class="box_text">技师申请</view>
				</view>
				<view class="box" @click="goNav('/my/shop/address?consortiaId='+consortiaId+'&userId=')">
					<image src="../../static/images/my/weizhi.png"></image>
					<view class="box_text">位置记录</view>
				</view>
				<view class="box" @click="goNav('/my/shop/qiandao?consortiaId='+consortiaId+'&userId=')">
					<image src="../../static/images/my/qiandao.png"></image>
					<view class="box_text">签到记录</view>
				</view>
				<view class="box" v-if="renzheng > 0" @click="goNav('/my/renzheng/index')">
					<image src="../../static/images/my/renzheng.png"></image>
					<view class="box_text">实名认证</view>
				</view>
				<view class="box" @click="goNav('/my/wallet/index')">
					<image src="../../static/images/my/baozhengjin.png"></image>
					<view class="box_text">我的钱包</view>
				</view>
				<view class="box" @click="goChat()">
					<image src="../../static/images/my/kefu.png"></image>
					<view class="box_text">联系客服</view>
				</view>
				<view class="box" @click="goNav('/my/help/feedbackIndex')">
					<image src="../../static/images/my/help.png"></image>
					<view class="box_text">帮助中心</view>
				</view>
				<view class="box" @click="goNav('/my/setting/index')">
					<image src="../../static/images/my/set1.png"></image>
					<view class="box_text">设置中心</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// ordersScore: 0,
				// creditScore: 0,
				// phone: '',
				openId: '',
				avatar: '../../static/logo.png',
				isLogin: true,
				userName: '匿名',
				money: 0, //账户余额
				toDayMoney: 0, //今日收益
				monthMoney: 0, //本月收益
				sumMoney: 0, //累计收益
				cashMoney: 0, //本月提现
				userId: '',
				// isVip: false,
				invitationCode: '', //邀请码
				// succeedRate: 0,
				// sumCount: 0,
				renzheng: 0,
				// bzjCheck: '否',
				// XCXIsSelect: '否',
				// shopSel: '否',
				// isCashDeposit: ''
				companyId: '',
				consortiaId: '',
				consortiaNo: ''
			}
		},
		onLoad() {
			this.XCXIsSelect = this.$queue.getData("XCXIsSelect");
			this.shopSel = this.$queue.getData('shopSel');
		},
		onShow() {
			this.bzjCheck = this.$queue.getData("bzjCheck");
			this.userId = uni.getStorageSync('userId')
			if (this.userId) {
				this.isLogin = false
				this.getUserInfo()
				this.getrenzheng()
				// this.getCount();
				this.getAmount()
				this.getMoney()
				// this.getIsVip()

			} else {
				this.ordersScore = 0;
				this.creditScore = 0;
				this.succeedRate = 0;
				this.sumCount = 0;
				this.isLogin = true
				this.userName = '匿名'
				this.money = 0
				this.toDayMoney = 0
				this.monthMoney = 0
				this.sumMoney = 0
				this.cashMoney = 0
				this.avatar = '../../static/logo.png'
			}

		},
		filters: {
			formatPrice(data) {
				if (typeof(data) === "number") {
					return parseFloat(parseFloat(data) * 100).toFixed();
				}
				return 0.00;
			}
		},
		methods: {
			goChat() {
				let kefu = this.$queue.getData('kefu'); // 用户端联系方式 1 手机号 2企业微信
				let kefuPhone = this.$queue.getData('kefuPhone');
				if (kefu == 1) {
					uni.makePhoneCall({
						phoneNumber: kefuPhone //仅为示例
					});
				} else {
					// #ifdef MP-WEIXIN
					let that = this
					try {
						wx.openCustomerServiceChat({
							extInfo: {
								url: that.$queue.getData('kefuUrl')
							},
							corpId: that.$queue.getData('kefuAppId'),
							success(res) {},
							fail(res) {
								console.error(res)
							}
						})
					} catch (error) {
						console.error("catchcatch" + error)
						uni.showToast({
							title: '请更新至微信最新版本'
						});
					}
					// #endif
					// #ifndef MP-WEIXIN
					let url = this.$queue.getData('kefuUrl');
					if (url.indexOf('/pages/') !== -1 || url.indexOf('/my/') !== -1) {
						uni.navigateTo({
							url
						});
					} else {
						//#ifndef H5
						uni.navigateTo({
							url: '/pages/index/webView?url=' + url
						});
						//#endif
						//#ifdef H5
						window.location.href = url;
						//#endif
					}
					// #endif
				}
			},
			//跳转用户端
			gouser() {
				wx.navigateToMiniProgram({
					appId: 'wx36626f7398972421',
					path: '/pages/index/index',
					envVersion: 'release', // 打开正式版
					success(res) {
						// 打开成功
					},
					fail: function(err) {
						console.log(err);
					}
				})
			},
			getCount() {
				this.$Request.get("/app/artificer/selectArtificerIndex").then(res => {
					if (res.code == 0) {
						this.succeedRate = res.data.succeedRate;
						console.log(this.succeedRate)
						this.sumCount = res.data.sumCount;
					}
				})
			},
			goQian() {
				uni.navigateTo({
					url: '/my/wallet/index'
				})
			},
			bindFb() {
				let renzheng = uni.getStorageSync('renzheng')
				console.log(this.userId, renzheng)

				if (this.userId) {
					uni.navigateTo({
						url: '/my/publish/editor'
					})
				} else {
					uni.showModal({
						title: '提示',
						content: '您还未实名认证,请先认证',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/my/renzheng/index'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			},
			goNav(e, name) {
				console.log(e)
				if (this.userId) {
					uni.navigateTo({
						url: e
					})
				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			},
			goLogin(e) {
				uni.navigateTo({
					url: e
				})
			},
			//我的收益
			getAmount() {
				this.$Request.get("/app/consortia/selectConsortiaMoneyData").then(res => {
					if (res.code == 0) {
						this.toDayMoney = res.data.toDayMoney //今日收益
						this.monthMoney = res.data.monthMoney //本月收益
						this.sumMoney = res.data.sumMoney //累计收益
						this.cashMoney = res.data.cashMoney //本月提现
					}
				});
			},
			getMoney() {
				this.$Request.get("/app/userMoney/selectMyMoney").then(res => {
					if (res.code == 0) {
						this.money = res.data.money //账户余额
					}
				});
			},
			getUserInfo() {
				this.$Request.get("/app/user/selectUserById").then(res => {
					if (res.code == 0) {
						this.userName = res.data.userName
						this.invitationCode = res.data.invitationCode
						this.avatar = res.data.avatar ? res.data.avatar : '../../static/logo.png'
						this.consortiaId = res.data.consortiaId

						this.phone = res.data.phone;
						this.openId = res.data.openId;

						//保证金
						// if (res.data.isCashDeposit == 1 || res.data.isCashDeposit == null) {
						// 	this.isCashDeposit = 1
						// 	uni.setStorageSync("isCashDeposit", this.isCashDeposit)
						// } else if (res.data.isCashDeposit == 2) {
						// 	this.isCashDeposit = 2
						// 	uni.setStorageSync("isCashDeposit", this.isCashDeposit)
						// } else if (res.data.isCashDeposit == 3) {
						// 	this.isCashDeposit = 3
						// 	uni.setStorageSync("isCashDeposit", this.isCashDeposit)
						// }

						uni.setStorageSync('avatar', res.data.avatar)
						uni.setStorageSync('invitationCode', res.data.invitationCode)
						uni.setStorageSync('consortiaId', res.data.consortiaId)

						this.getArtificer()

					}
				});


			},
			getrenzheng() {
				//实名认证
				this.$Request.getT("/app/company/selectCompanyByUserId").then(res => {
					if (res.code == 0&&res.data) {
						if (res.data.status == 0 || res.data.status == null) {
							this.renzheng = '0'
							uni.setStorageSync("renzheng", this.renzheng)
						} else if (res.data.status == 1) {
							this.renzheng = '1'
							uni.setStorageSync("renzheng", this.renzheng)
						} else if (res.data.status == 2) {
							this.renzheng = '2'
							uni.setStorageSync("renzheng", this.renzheng)
						} else if (res.data.status == 3) {
							this.renzheng ='3'
							uni.setStorageSync("renzheng", this.renzheng)
						}
						this.companyId = res.data.companyId
					}else{
						this.renzheng = '0'
						uni.setStorageSync("renzheng", this.renzheng)
					}
				});
			},
			//获取技师的信息
			getArtificer() {
				this.$Request.getT("//app/consortia/selectConsortiaByUserId?consortiaId=" + this.consortiaId).then(res => {
					if (res.code == 0) {
						this.consortiaNo = res.data.consortiaNo
						// this.creditScore = res.data.creditScore ? res.data.creditScore : 0;
						// this.ordersScore = res.data.ordersScore ? res.data.ordersScore : 0;
						// // uni.setStorageSync("status", res.data.status)
						// uni.setStorageSync('artificerId', res.data.artificerId)
					}
				});
			},
			//会员
			getIsVip() {
				this.$Request.get("/app/UserVip/isUserVip").then(res => {
					if (res.code == 0) {
						this.isVip = res.data
						uni.setStorageSync('isVIP', res.data)
					}
				});
			},
			//退出登录
			TuiLogin() {
				let that = this
				if (that.userId) {
					uni.showModal({
						title: '提示',
						content: '确定退出登录吗？',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.removeStorageSync('userName')
								uni.removeStorageSync('avatar')
								uni.removeStorageSync('userId')
								uni.removeStorageSync('token')
								uni.removeStorageSync('phone')
								uni.removeStorageSync('zhiFuBaoName')
								uni.removeStorageSync('zhiFuBao')
								uni.removeStorageSync('invitationCode')
								uni.removeStorageSync('unionId')
								uni.removeStorageSync('openId')
								uni.removeStorageSync('isVIP')
								uni.showToast({
									title: '退出成功！',
									icon: 'none'
								})
								that.isLogin = true
								that.userName = '匿名'
								that.money = 0
								that.dayMoney = 0
								that.monthMoney = 0
								that.cashMoney = 0
								that.avatar = '../../static/logo.png'
								that.userId = uni.getStorageSync('userId')
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}


			},

		}
	}
</script>

<style lang="scss">
	page {
		background-color: #FFFFFF;
	}

	.bg {
		background: #FFFFFF;
	}

	.headtop {
		background: linear-gradient(to bottom, #05C25C 5%, #FFFFFF 80%, );
	}

	.bgs {
		background: linear-gradient(to bottom, #FFFFFF 15%, #F2F2F2 80%, );
	}

	.bgl {
		background: linear-gradient(to bottom, #BAEED2 10%, #FFFFFF 25%, );
		width: 92%;
		margin: 20rpx auto;
		border-radius: 24rpx;
		padding: 30rpx;
		margin-top: 40rpx;
	}

	.money_text {
		font-size: 48rpx;
		font-family: DINPro;
		font-weight: 500;
		color: #161616;
	}

	.moneybox {
		width: 690upx;
		margin: 0 auto;
		background-image: url('https://anmo.xianmxkj.com/file/uploadPath/2022/12/29/b9f2712917cbe6bda8bf830e7242aceb.png');
		background-size: 100% 100%;
		background-repeat: no-repeat;
	}


	.xflist {
		width: 150upx;
		height: 50upx;
		background: #2FB57A;
		border-radius: 5upx;
		text-align: center;
		line-height: 50upx;
		color: #FFFFFF;

		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: bold;
	}

	.box {
		width: 25%;
		text-align: center;
		padding-bottom: 20rpx;

		.box_text {
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #090909;
			margin-top: 10rpx;
		}

		image {
			width: 70rpx;
			height: 70rpx;
		}
	}

	.btn {
		border: 1rpx solid #999999;
		color: #999999;
		border-radius: 39rpx;
		padding: 10rpx 25rpx;
	}

	.btn1 {
		border: 1rpx solid #2FB57A;
		color: #2FB57A;
		border-radius: 39rpx;
		padding: 10rpx 25rpx;
	}

	.xinshou {
		background: #FFF1D7;
		color: #EDBD6B;
		display: inline-flex;
		border-radius: 12rpx;
		padding: 5rpx 12rpx;
		font-size: 24rpx;
	}

	.title {
		font-size: 32rpx;
		font-weight: bold;
		margin-left: 10rpx;
	}

	.label {
		// background: #FFFFFF;
		background: linear-gradient(to right, #f0dfc4 5%, #f8c783 80%);
		color: #a06411;
		display: inline-flex;
		align-items: center;
		padding: 0rpx 15rpx;
		border-radius: 50rpx;
		margin-left: 15rpx;
	}
</style>
